import pymysql
db = pymysql.connect(
    host='localhost',
    user='root',
    password='123456',
    port=3306,
    database='hrtest',
    charset='utf8'
)

try:
    with db.cursor() as cursor:
        for i in range(10):
            sql = "INSERT INTO person (username, age, sex, high) VALUES (%s, %s, %s,%s)"
            list1 = []
            print("请输入用户名：")
            username = input()
            list1.append(username)
            print("请输入年龄：")
            age = int(input())
            list1.append(age)
            print("请输入性别：")
            sex = input()
            list1.append(sex)
            print("请输入身高：三位数字两位小数")
            high = float(input())
            list1.append(high)
            list1 = tuple(list1)
            cursor.execute(sql, list1)
            db.commit()
            print("数据插入成功！")
except Exception as e:
    print(f"第{i+1}次数据插入失败！", e)
finally:
    cursor.close()
    db.close()